package com.twu.biblioteca.menu;


public class Menu {

    public enum OPTIONS {

        LIST_BOOKS(1) {
            @Override
            public void execute() {
                new DisplayListOfBooksOption().execute();
            }
        }, CHECK_OUT_BOOK(2) {
            @Override
            public void execute() {
                new CheckOutBookOption().execute();
            }
        }, CHECK_MEMBERSHIP_DETAILS(3) {
            @Override
            public void execute() {
                new CheckMembershipDetailsOption().execute();
            }
        } ,LIST_MOVIES(4){
            @Override
            public void execute() {
                new ListOfMoviesOption().execute();
            }
        }, QUIT(5) {
            @Override
            public void execute() {
                new QuitOption().execute();
            }
        }, INVALID(6) {
            @Override
            public void execute() {
                new InvalidOption().execute();
            }
        };

        private final int selectedOption;

        OPTIONS(int selectedOption) {
            this.selectedOption = selectedOption;
        }

        public abstract void execute();

        protected OPTIONS selectOption(int userChoice) {
            for (OPTIONS option : OPTIONS.values()) {
                if (userChoice == option.selectedOption)
                    return option;
            }
            return OPTIONS.INVALID;
        }


    }

    private OPTIONS option = OPTIONS.LIST_BOOKS;

    public OPTIONS processUserInput(int userChoice) {
        return option.selectOption(userChoice);
    }

    public void printWelcomeMessage() {
        System.out.println("***********Hello Welcome***********\n" +
                "\n Select the following menu options\n" +
                "1. To see a list of all available books.\n" +
                "2. To check out a book.\n" +
                "3. To check your membership details \n" +
                "4. To see a list of movies available \n" +
                "5. To exit \n" +
                "\n Enter your choice: ");
    }

}
